#include <51func.h>
int main(int argc, char *argv[])
{
    // ./6_transfile_B 1.pipe
    ARGS_CHECK(argc,2);
    int fd_pipe = open(argv[1],O_RDONLY);
    char filename[4096] = {0};
    // 收文件名
    int length;
    read(fd_pipe,&length,sizeof(int));
    read(fd_pipe,filename,length);
    char pathname[8192] = {0};
    sprintf(pathname,"%s/%s","dir1",filename);
    mkdir("dir1",0777);
    int fd_file  = open(pathname,O_RDWR|O_CREAT|O_TRUNC,0666);
    
    // 收文件内容
    char buf[4096];
    while(1){
        memset(buf,0,sizeof(buf));
        read(fd_pipe,&length,sizeof(int));
        if(length == 0){
            break;
        }
        read(fd_pipe,buf,length);
        write(fd_file,buf,length);
    }
    return 0;
}

